package TorrentClient;
import java.io.*;
import java.net.*;
public class Client {

	public void synchClient(String address, int port, String file){
		
		 Socket socket = null;
		 /*
		  * Server ip and port
		  */
		    
		    try {
				socket = new Socket(address, port);
				PrintWriter echoWriter = new PrintWriter(socket.getOutputStream(),true);
				echoWriter.println(file);
				echoWriter.println("#end#");
				echoWriter.close();
				

			} catch (UnknownHostException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (Exception e){
				System.out.println("Could not connect to tracker: "+address);
			}

		   

	}
	
	
public static void main(String[] args) throws IOException {
   Client temp = new Client();
   BufferedReader br = new BufferedReader(new FileReader("HashFile"));
   try {
       StringBuilder sb = new StringBuilder();
       String line = null;

       while ((line = br.readLine()) != null) {
         System.out.println(line.split(",")[2]);
         String address = line.split(",")[2];
         temp.synchClient(address, 4444, line);
       }
      
   } finally {
       br.close();
   }
   ClientThread clientThread = new ClientThread(50000);
   clientThread.start();
   
 // temp.synchClient("127.0.0.1",4444);
   
  // temp.receiveFile();
}
}